package com.bt.controller.admin;

import com.bt.constant.JwtClaimsConstant;
import com.bt.dto.SysUserLoginDTO;
import com.bt.entity.SysUser;
import com.bt.properties.JwtProperties;
import com.bt.result.Result;
import com.bt.service.IndexService;
import com.bt.utils.JwtUtil;
import com.bt.vo.BaseInfoVO;
import com.bt.vo.ConfigVO;
import com.bt.vo.ProfileVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description TODO
 * @Author 青
 * @Date 2023-04-28 22:18
 */
@RestController
@RequestMapping("/index")
@Api(tags = "后台基础模块")
@Slf4j
public class IndexController {
    @Autowired
    IndexService indexService;
    @Autowired
    JwtProperties jwtProperties;


    @PostMapping("/login")
    public Result login(@RequestBody SysUserLoginDTO sysUserLoginDTO) {
        log.info("员工登录: {}", sysUserLoginDTO);

        SysUser sysUser = indexService.login(sysUserLoginDTO);

        Map<String, Object> claims = new HashMap<>();
        claims.put(JwtClaimsConstant.SYSUser_ID, sysUser.getId());

        String token = JwtUtil.creteJWT(jwtProperties.getAdminSecretKey(),
                jwtProperties.getAdminTtl(), claims);


        HashMap<String, String> map = new HashMap<String, String>();

        map.put("token", token);

        return Result.success(map);
//        claims.put(JwtClaimsConstant.LOGIN_NAME, sysUser.getLoginName());
//        claims.put(JwtClaimsConstant.PASSWORD, sysUser.getPassword());
//        claims.put(JwtClaimsConstant.NAME, sysUser.getName());
//        claims.put(JwtClaimsConstant.EMAIL, sysUser.getEmail());
//        claims.put(JwtClaimsConstant.PHONE, sysUser.getPhone());
//        claims.put(JwtClaimsConstant.LOGIN_IP, sysUser.getLoginIp());
//        claims.put(JwtClaimsConstant.CREATE_DATE, sysUser.getCreateDate());
//        claims.put(JwtClaimsConstant.UPDATE_DATE, sysUser.getUpdateDate());
//        claims.put(JwtClaimsConstant.DEL_FLAG, sysUser.getDelFlag());
//        claims.put(JwtClaimsConstant.ROLE_ID, sysUser.getRoleId());
//        claims.put(JwtClaimsConstant.STATUS, sysUser.getStatus());
//        claims.put(JwtClaimsConstant.DEFAULT_DATE, sysUser.getDefaultData());


    }

    /**
     * 主页统计信息
     *
     * @return
     */
    @ApiOperation("主页统计信息")
    @GetMapping("/baseInfo")
    public Result<BaseInfoVO> baseInfo() {
        BaseInfoVO baseInfoVO = indexService.baseInfo();

        return Result.success(baseInfoVO);
    }

    /**
     * 获取用户资料
     *
     * @return
     */
    @PostMapping("/profile")
    @ApiOperation("获取用户资料")
    public Result<ProfileVO> profile() {
        log.info("获取用户资料...");

        ProfileVO profileVO = indexService.getUserData();

        return Result.success(profileVO);
    }

    /**
     * 获取系统配置
     *
     * @return
     */

    @GetMapping("/getConfig")
    @ApiOperation("获取系统配置")
    public Result<ConfigVO> getConfig() {
        ConfigVO configVO = new ConfigVO();

        configVO.setLogin_title("优点达");
        configVO.setLogin_bg("src\\main\\resources\\static\\1.jpg");
        configVO.setSystem_name("优点达");
        configVO.setSystem_logo("src\\main\\resources\\static\\1.jpg");
        configVO.setWeb_ico("src\\main\\resources\\static\\1.jpg");

        return Result.success(configVO);
    }
}
